﻿using LitJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class PartStateBehaviour : ShipEventBehaviours
{
    public int m_PartID = -1;
    public PartStateBehaviour()
    {
        m_BehavioursType = BehavioursType.PartState;
    }
    public override void Init()
    {
    }
    public override void BindShip(Ship ship)
    {
        base.BindShip(ship);
    }
    public virtual string GetParameterName(int type)
    {
        return "无";
    }

    protected Part GetPart()
    {
        if (m_PartID == -1 || m_Ship == null)
            return null;

        return m_Ship.FindPart(m_PartID);
    }
    public override void Execute()
    {
        base.Execute();
        var part = GetPart();
        if (part == null)
            return;

        part.SetParameter(m_Behaviour);
    }
    public override JsonData Save()
    {
        JsonData root = base.Save();
        root["PartID"] = m_PartID;
        return root;
    }
    public override bool Load(JsonData root)
    {
        if (!base.Load(root))
            return false;

        IDictionary<string, JsonData> rootObj = root.ValueAsObject();

        if (rootObj.ContainsKey("PartID"))
            m_PartID = rootObj["PartID"].ValueAsInt();
        return true;
    }
}